package data;

import constants.TileTypes;

import javax.swing.*;
import java.util.HashMap;

/**
 * data
 *
 * @author Jared Moore
 * @date 10/8/13
 */
public class Tile
{
	public static final HashMap<TileTypes, Integer[]> TILE_VALUES = new HashMap<>();
	public static final HashMap<TileTypes, ImageIcon> TILE_ICONS = new HashMap<>();
	private final TileTypes type;
	private final boolean isTown;
	private Integer[] values = new Integer[3];
	private Player owner;
	private ImageIcon icon;

    static
    {
	    Integer[] plainValues = {2, 3, 1},
	    riverValues = {4, 2, 0},
	    mountain1Values = {1, 1, 2},
	    mountain2Values = {1, 1, 3},
	    mountain3Values = {1, 1, 4};
	    TILE_VALUES.put(TileTypes.PLAIN, plainValues);
	    TILE_VALUES.put(TileTypes.RIVER, riverValues);
	    TILE_VALUES.put(TileTypes.ONE_MOUNTAIN, mountain1Values);
	    TILE_VALUES.put(TileTypes.TWO_MOUNTAINS, mountain2Values);
	    TILE_VALUES.put(TileTypes.THREE_MOUNTAINS, mountain3Values);

		TILE_ICONS.put(TileTypes.PLAIN, new ImageIcon("res/tiles/plain.jpg"));
	    TILE_ICONS.put(TileTypes.TOWN, new ImageIcon("res/tiles/town.jpg"));
	    TILE_ICONS.put(TileTypes.RIVER, new ImageIcon("res/tiles/river.jpg"));
	    TILE_ICONS.put(TileTypes.ONE_MOUNTAIN, new ImageIcon("res/tiles/mountain1.jpg"));
	    TILE_ICONS.put(TileTypes.TWO_MOUNTAINS, new ImageIcon("res/tiles/mountain2.jpg"));
	    TILE_ICONS.put(TileTypes.THREE_MOUNTAINS, new ImageIcon("res/tiles/mountain3.jpg"));
    }

	public Tile(TileTypes type)
	{
        owner = null;
		this.type = type;
		if (type == TileTypes.TOWN)
		{
			isTown = true;
			icon = TILE_ICONS.get(type);
		}
		else
		{
			isTown = false;
			values = TILE_VALUES.get(type);
			icon = TILE_ICONS.get(type);
		}

	}

	public void placeMule(MULE freeMule)
	{

	}

	public TileTypes getType()
	{
		return type;
	}

	public int getFood()
	{
		return values[0];
	}

	public int getEnergy()
	{
		return values[1];
	}

	public int getOre()
	{
		return values[2];
	}

	public Player getOwner()
	{
		return owner;
	}

	public void setOwner(Player owner)
	{
		this.owner = owner;
	}

	public ImageIcon getIcon()
	{
		return icon;
	}

	public boolean isTown()
	{
		return isTown;
	}
    public boolean hasOwner()
    {
        return this.owner!=null;
    }
}
